<?php
class WallModel extends Zend_Db_Table_Abstract {
	
	protected $_name = 'wall';
	protected $_id = 'id';
	
	public function listwallpost($user_id){
		$db = Zend_Registry::get('connectDB');
		$select = $db->select()
					->from(array('w'=>'wall'),array('wall_id'=>'w.id',
													'type'=>'w.type',
													'user_id'=>'w.user_id',
													'content'=>'w.content',
													'friend_id'=>'w.friend_id',
													'photo'=>'w.photo',
													'time'=>'w.time'))
					->join(array('u'=>'user'),'u.id = w.user_id',array('username'=>'u.username',
																		'fullname'=>'u.fullname',
																		'avatar'=>'u.avatar'))
					->where('w.friend_id = '.$user_id)
					->order('w.id DESC');
		$list = $db->fetchAll($select);
		return $list;
	}
	
	public function add($wallpost){
		$model = new WallModel();
		if ($wallpost['type']==1)
			$data = array('type'=>$wallpost['type'],'user_id'=>$wallpost['user_id'],'content'=>$wallpost['content'],'friend_id'=>$wallpost['friend_id']);
		if ($wallpost['type']==2)
			$data = array('type'=>$wallpost['type'],'user_id'=>$wallpost['user_id'],'photo'=>$wallpost['photo'],'friend_id'=>$wallpost['friend_id']);
		$id = $model->insert($data);
		return $id;
	}
	
	public function selectWall( $wall_id ){
		$db = Zend_Registry::get('connectDB');
		$select = $db->select()
					->from(array('w'=>'wall'),array('wall_id'=>'w.id',
													'type'=>'w.type',
													'user_id'=>'w.user_id',
													'content'=>'w.content',
													'friend_id'=>'w.friend_id',
													'photo'=>'w.photo',
													'time'=>'w.time'))
					->join(array('u'=>'user'),'u.id = w.user_id',array('username'=>'u.username',
																		'fullname'=>'u.fullname',
																		'avatar'=>'u.avatar'))
					->where('w.id = '.$wall_id);
		$list = $db->fetchAll($select);
		return $list[ 0 ];
	}
	
	
}